import { Form, Input, Modal, Select } from 'antd';
import { useState, useEffect, useRef } from 'react'
export default function AddModal(props) {

    const form = useRef(null);
    const [addFrom, setAddFrom] = useState()
    //const [form] = Form.useForm();

    useEffect(() => {
        // FetchHelper.postJson(`/admin-api/ybyj/presetDept`, {
        //            addFrom
        //         }).then(resp => {

        //         })
        
        console.log("addFrom",addFrom)
    }, [addFrom,props])

    const handleOk = () => {
        form.current.validateFields().then((values) => {
            const addDept = {
                ...values,
                ancestors: props.preset_dept.ancestors,
                parentId: props.preset_dept.id
            }
            console.log(addDept)
            setAddFrom(addDept)
            form.current.resetFields(); // 重置表单字段的值
            props.onCancel?.()
        }).catch((errorInfo) => {
            alert(`表单校验失败:' ${errorInfo} '`);
        });
    };

    return (
        <Modal
            width={600}
            mask={false}
            onOk={handleOk}
            bodyStyle={{ height: 200 }}
            title="新增部门"
            visible={props.open}
            onCancel={props.onCancel}
        >
            <Form ref={form}>
                <Form.Item label="请输入部门名称" name='deptName' rules={[{ required: true, message: '请输入部门名称' }]}>
                    <Input />
                </Form.Item>
                <Form.Item label="部门权限" name='code' rules={[{ required: true, message: '请选择部门权限' }]}>
                    <Select>
                        <Select.Option label="暂无" value="暂无">
                            暂无
                        </Select.Option>
                    </Select>
                </Form.Item>
            </Form>
        </Modal>
    );
    /* return <Modal width={600} 
    mask={false}
    onOk={e => {
        form.validateFields().then(values => {
            const addDept = values
            // addDept.ancestors = props.preset_dept.ancestors,
            // addDept.parentId = props.preset_dept.id
            console.log(values)
            setAddFrom()
        })
        props.onCancel?.()
    }} 
    bodyStyle={{
        height: 200
    }} 
    title="新增部门" open={props.open} onCancel={e => props.onCancel?.()}>
        <Form ref={form}>
            <Form.Item label="请输入部门名称" name='deptName'>
                <Input></Input>
            </Form.Item>
            <Form.Item label="部门权限" name='code'>
                <Select>
                    <Select.Option label="暂无" value="暂无">

                    </Select.Option>
                </Select>
            </Form.Item>
        </Form>
    </Modal>; */
}